package routes

import (
	"fmt"
	v1 "ginblog/api/v1"
	"ginblog/middleware"
	"ginblog/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	r := gin.Default()
	r.Use(middleware.Logger())
	router := r.Group("api/v1")
	{
		router.POST("login", v1.LogInfo)

		router.GET("user/get", v1.GetUser)

		router.GET("category/get", v1.GetCategory)

		router.GET("article/list", v1.GetArticleList)
		router.GET("article/get/:id", v1.GetArticle)
		router.GET("article/catearticle/:id", v1.GetCateArticle)

	}

	auth := r.Group("api/v1")
	auth.Use(middleware.JwtToken())
	{
		auth.POST("user/add", v1.AddUser)
		auth.DELETE("user/del/:id", v1.DeletelUser)
		auth.PUT("user/edt/:id", v1.EditUser)

		auth.POST("category/add", v1.AddCategory)
		auth.DELETE("category/del/:id", v1.DeletelCategory)
		auth.PUT("category/edt/:id", v1.EditCategory)

		auth.POST("article/add", v1.AddArticle)

		auth.DELETE("article/del/:id", v1.DeletelArticle)
		auth.PUT("article/edt/:id", v1.EditArticle)

	}

	fmt.Println(utils.DbHost)
	err := r.Run(utils.HttpPort)
	if err != nil {
		fmt.Printf("检查配置:%v", err)
	}

}
